<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('员工合同列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>姓名：</label>
                                <input type="text" id="stfName" name="stfName"/>
                            </li>
                            <li>
                                <label>部门：</label>
                                <input type="text" name="stfDep"/>
                            </li>
                            <li>
                                <label>证件号：</label>
                                <input type="text" name="stfIdCard"/>
                            </li>
                            <li>
                                <label>合同编号：</label>
                                <input type="text" name="stfContractId"/>
                            </li>
                            <li>
                                <label>合同公司：</label>
                                <input type="text" name="stfContractCompany"/>
                            </li>
                            <li>
                                <label>合同类型：</label>
                                <select name="stfContractType">
                                    <option value>所有</option>
                                </select>
                            </li>
                            <li>
                                <label>期限类型：</label>
                                <select name="stfDeadlineType">
                                    <option value="">所有</option>
                                    <option value="-1">代码生成请选择字典属性</option>
                                </select>
                            </li>
                            <li>
                                <label>合同开始日期：</label>
                                <input type="text" class="time-input" placeholder="请选择合同开始日期" name="stfContractStartDate"/>
                            </li>
                            <li>
                                <label>合同结束日期：</label>
                                <input type="text" class="time-input" placeholder="请选择合同结束日期" name="stfContractEndDate"/>
                            </li>
                            <li>
                                <label>合同签订日期：</label>
                                <input type="text" class="time-input" placeholder="请选择合同签订日期" name="stfContractSignDate"/>
                            </li>
                            <li>
                                <label>合同中止日期：</label>
                                <input type="text" class="time-input" placeholder="请选择合同中止日期" name="stfContractTerminateDate"/>
                            </li>
                            <li>
                                <label>合同已签订次数：</label>
                                <input type="text" name="stfContractSignCount"/>
                            </li>
                            <li>
                                <label>续签审批状态：</label>
                                <select name="stfExamineStatus">
                                    <option value>所有</option>
                                    <option value="">已审批</option>
                                    <option value="">未审批</option>
                                </select>
                            </li>
                            <li>
                                <label>合同状态：</label>
                                <select name="stfContractStatus">
                                    <option value="">所有</option>
                                    <option value="-1">代码生成请选择字典属性</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="staff:contract:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="staff:contract:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="staff:contract:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-success" onclick="importExcel()" shiro:hasPermission="staff:contract:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="staff:contract:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info single disabled" onclick="importAttachment()" >
                    <i class="fa fa-upload"></i> 上传附件
                </a>
                <a class="btn btn-danger single disabled" onclick="exportAttachment()" >
                    <i class="fa fa-download"></i> 下载附件
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('staff:contract:edit')}]];
        var removeFlag = [[${@permission.hasPermi('staff:contract:remove')}]];
        var prefix = ctx + "staff/contract";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                uniqueId:"stfId",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "员工合同",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'stfId',
                    title: '工号'
                },
                {
                    field: 'stfName',
                    title: '姓名'
                },
                {
                    field: 'stfDep',
                    title: '部门'
                },
                {
                    field: 'stfIdCard',
                    title: '证件号'
                },
                {
                    field: 'stfContractId',
                    title: '合同编号'
                },
                {
                    field: 'stfContractCompany',
                    title: '合同公司'
                },
                {
                    field: 'stfContractType',
                    title: '合同类型',
                    visible: false
                },
                {
                    field: 'stfDeadlineType',
                    title: '期限类型',
                    visible: false
                },
                {
                    field: 'stfContractStartDate',
                    title: '合同开始日期'
                },
                {
                    field: 'stfContractEndDate',
                    title: '合同结束日期'
                },
                {
                    field: 'stfContractSignDate',
                    title: '合同签订日期',
                    visible: false
                },
                {
                    field: 'stfContractTerminateDate',
                    title: '合同中止日期',
                    visible: false
                },
                {
                    field: 'stfContractSignCount',
                    title: '合同已签订次数',
                    visible: false
                },
                {
                    field: 'stfExamineStatus',
                    title: '续签审批状态',
                    visible: false
                },
                {
                    field: 'stfContractStatus',
                    title: '合同状态',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.stfId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.stfId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**
         * 导入
         * */
        function importExcel(formId, width, height) {
            table.set();
            var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
            var _width = $.common.isEmpty(width) ? "400" : width;
            var _height = $.common.isEmpty(height) ? "230" : height;
            layer.open({
                type: 1,
                area: [_width + 'px', _height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: '导入' + table.options.modalName + '数据',
                content: $('#' + currentId).html(),
                btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
                // 弹层外区域关闭
                shadeClose: true,
                btn1: function(index, layero){
                    var file = layero.find('#drfile').val();
                    if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){
                        $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                        return false;
                    }
                    var index = layer.load(2, {shade: false});
                    $.modal.disable();
                    var formData = new FormData(layero.find('form')[0]);
                    $.ajax({
                        url:prefix + "/importExcel",
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        type: 'POST',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $.modal.closeAll();
                                $.modal.alertSuccess(result.msg);
                                $.table.refresh();
                            } else if (result.code == web_status.WARNING) {
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertWarning(result.msg)
                            } else {
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertError(result.msg);
                            }
                        }
                    });
                }
            });
        }

        /**
         * 上传合同附件
         * */
        function importAttachment() {
            var stfIds = $.table.selectColumns("stfId");
            layer.open({
                type: 1,
                area: ['400px','230px'],
                fix:false,
                maxmin:true,
                shade:0.3,
                title:'上传合同附件',
                content:$('#importAddTpl').html(),
                btn:['<i class="fa fa-check"></i>导入','<i class="fa fa-remove"></i>取消'],
                //弹层外区域关闭
                shadeClose:true,
                btn1:function (index,layero) {
                    var filename = layero.find('#file').val();
                    if(filename == ''){
                        $.modal.msgWarning("请选择需要上传的文件！");
                        return false;
                    }
                    var index = layer.load(2,{shade:false});
                    $.modal.disable();
                    var formData = new FormData(layero.find('form')[0]);
                    formData.append("stfIds", stfIds);
                    $.ajax({
                        url:prefix + "/importAttachment",
                        data:formData,
                        cache:false,
                        contentType:false,
                        processData:false,
                        type:'POST',
                        success:function( result){
                           if(result.code == web_status.SUCCESS){
                               $.modal.closeAll();
                               $.modal.alertSuccess(result.msg);
                               $.table.refresh();
                           }else if (result.code == web_status.WARNING){
                               layer.close(index);
                               $.modal.enable();
                               $.modal.alertWarning(result.msg);
                           }else{
                               layer.close(index);
                               $.modal.enable();
                               $.modal.alertError(result.msg);
                           }
                        }
                    })
                }
            })
        }
        /**
         * 下载合同附件
         * */
        function exportAttachment() {
            var stfId = $.table.selectColumns("stfId");
            var rows = $.table.selectColumns("stfName");
            var data = [];
            data.push({"name": "stfId", "value": stfId});
            $.modal.confirm("确认要下载 "+rows+" 的合同附件吗?",function () {
                $.ajax({
                    url:prefix + "/exportAttachment",
                    type:"post",
                    dataType:"json",
                    data:data,/*这里用于传数据的*/
                    beforeSend:function () {
                        $.modal.loading("开始执行，请稍候...");
                        $.modal.disable();
                    },
                    success:function (result) {
                        if (typeof callback == "function"){
                            callback(result);
                        }
                        if(result.code == web_status.SUCCESS){
                            window.location.href = prefix + "/downloadAttachment?downloadPath=" + result.data;
                            $.modal.closeLoading();
                        }else{
                            $.modal.closeLoading();
                            $.modal.alertError(result.msg);
                            $.table.refresh();
                        }
                    }
                })
            }
        );
    }
        //导出员工合同
        function exportExcel(){
            var rows=$.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            };
            $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function() {
                var url = table.options.exportUrl;
                var data = { "ids": rows.join() };
                $.modal.loading("正在导出数据，请稍后...");
                $.post(url,data,function (res) {
                    if (res.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
                    } else if (res.code == web_status.WARNING) {
                        $.modal.alertWarning(res.msg)
                    } else {
                        $.modal.alertError(res.msg);
                    }
                    $.modal.closeLoading();
                })
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="drfile" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

<script id="importAddTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-l">
            <input style="margin-left: 20px" type="file" id="file" name="file"/>
        </div>
    </form>
</script>
</html>